
#ifndef __BROKER_4_SERVER_H
#define __BROKER_4_SERVER_H

#include <apr_atomic.h>
#include "../db/DBArbitrator.h"
#include "../crypt/RSAKeyPair.h"
#include "HTTPServer.h"
#include "Broker4.h"

#define BROKERNAME "broker"

class Broker4Server : public HTTPServer
{
   public:
      Broker4Server(int inoofthreads, int iportno, const char *ihostname, apr_pool_t *upperpool) :
         HTTPServer(inoofthreads, iportno, ihostname, upperpool) {}
      ~Broker4Server() {}
      apr_table_t *GetEncryptedHeaders(apr_table_t *plainheader, int i, apr_pool_t *mp, const char *buffer, apr_size_t length);
      //int DivineMeaning(EMessage *msgin, EMessage *msgout, int i, apr_pool_t *mp);
      int DivineMeaning(BrokerMessage *msgin, BrokerMessage *msgout, int i, apr_pool_t *mp);
      void GenerateConsole(int i, apr_pool_t *mp);
      void UnderstandPOSTData(apr_table_t *data);
      int ServeStreamFromSystemList(apr_table_t *htable, int i, apr_pool_t *mp, const char **systemwhitelist);
      void GETSession(int i, apr_pool_t *mp);
      void POSTSession(int i, apr_pool_t *mp);
      void BrokerSession(int i, apr_pool_t *mp);
      static void *ClientHandler(apr_thread_t *tthread, void *args);
      virtual functor GetClientHandlerFunction() const { return (functor)(&ClientHandler); }
      AllDBs *dbs;
};

#endif
